package com.malty.mall.controller.pms;

import com.malty.mall.common.CommonResult;
import com.malty.mall.domain.dto.query.BrandQuery;
import com.malty.mall.domain.dto.req.pms.PmsBrandParam;
import com.malty.mall.domain.dto.req.UpdateStatusReq;
import com.malty.mall.service.pms.IPmsBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author malty
 */
@RestController
@Api(tags = "品牌管理")
@RequestMapping("/brand")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PmsBrandController {
    private final IPmsBrandService pmsBrandService;

    @ApiOperation("创建品牌")
    @PostMapping("/create")
    public CommonResult<Boolean> createBrand(@RequestBody @Validated PmsBrandParam brandParam) {
        return CommonResult.success(pmsBrandService.create(brandParam));
    }

    @ApiOperation("编辑品牌")
    @PostMapping("/update")
    public CommonResult<Boolean> updateBrand(@RequestBody PmsBrandParam brandParam) {
        return CommonResult.success(pmsBrandService.updateById(brandParam));
    }

    @ApiOperation("编辑显示状态")
    @PostMapping("/update/show_status")
    public CommonResult<Boolean> showBrandStatus(@Validated @RequestBody UpdateStatusReq statusReq) {
        return CommonResult.success(pmsBrandService.updateShowStatus(statusReq));
    }

    @ApiOperation("编辑制造商状态")
    @PostMapping("/update/factory_status")
    public CommonResult<Boolean> factoryStatus(@Validated @RequestBody UpdateStatusReq statusReq) {
        return CommonResult.success(pmsBrandService.updateFactoryStatus(statusReq));
    }

    @ApiOperation("查询品牌")
    @GetMapping("/{id}")
    public CommonResult<PmsBrandParam> queryById(@PathVariable Integer id) {
        return CommonResult.success(pmsBrandService.getBrandById(id));
    }

    @ApiOperation("查询所有品牌")
    @GetMapping("/list_all")
    public CommonResult<List<PmsBrandParam>> listAll() {
        return CommonResult.success(pmsBrandService.listAll());
    }

    @ApiOperation("分页查询所有品牌")
    @GetMapping("/list")
    public CommonResult<List<PmsBrandParam>> listByPage(Integer pageNum, Integer pageSize, @RequestBody(required = false) BrandQuery brandQuery) {
        return CommonResult.success(pmsBrandService.listBrands(pageNum,pageSize,brandQuery));
    }

    @ApiOperation("删除品牌")
    @GetMapping("/delete/{id}")
    public CommonResult<Boolean> deleteById(@PathVariable Integer id) {
        return CommonResult.success(pmsBrandService.deleteById(id));
    }
}
